<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends Backend_Controller {

	protected $_title = 'My Profile';

	public function __construct() {
		parent::__construct();
		$this->load->model('actors_model', 'actors', true);
	}
		
	public function index($offset=0, $sort_by='name') {
		
		$data = array(
			'mainview' => 'index',
		) + $this->_get_header_data();
		
		if($_SESSION['actor']=="admin")
			$this->load->view('admin/template',$data);
		else if($_SESSION['actor']=="teacher")
			$this->load->view('teacher/template',$data);
		else if($_SESSION['actor']=="student")
			$this->load->view('student/template',$data);
		
	}
	
	function _crud_output($output = null) {
		if($_SESSION['actor']=="admin")
			$this->load->view('admin/template_crud.php',$output);    
		else if($_SESSION['actor']=="teacher")
			$this->load->view('teacher/template_crud.php',$output);    
		else if($_SESSION['actor']=="student")
			$this->load->view('student/template_crud.php',$output);    
        
    }

	function users_display(){
		$crud = new grocery_CRUD();
		$crud->set_model('user_actor_model');
		$crud->set_theme('flexigrid');
        $crud->set_table('actors');
        $crud->set_subject('My Profile');
		$crud->unset_add();
		$crud->unset_delete();
		$crud->unset_back_to_list();
		
		$crud->columns('name','username');
		$crud->display_as('name','Hak Akses');
		$crud->required_fields('name','username');
		$crud->change_field_type('password','password');
		
		$crud->callback_edit_field('name',array($this,'callback_edit_name'));
		$crud->callback_edit_field('password',array($this,'callback_edit_password'));
		$crud->fields('name','username','password');

        $output = $crud->render();
        $this->_crud_output($output);	
	}
	
	function callback_edit_password(){
		return '<input type="password" maxlength="50" value="" name="password" style="width:400px"> ( biarkan kosong = tidak mengganti password )';
	}
	
	function callback_edit_name($value){
		return '<input type="name" readonly maxlength="50" value="'. $value .'" name="name" style="width:400px"> ( readonly )';
	}
	
}
